package com.example.rdcproject.ving.notes.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class DBUtils {

    //数据库地址
    private static String url="jdbc:mysql://localhost:3306/demo?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC";
    //用户名
    private static String user="root";
    //密码
    private static String password="123456";
    //驱动名称
    private static String jdbcName="com.mysql.cj.jdbc.Driver";


    /**
     * 获取数据库连接
     * @return
     * @throws Exception
     */
    public static Connection getConnection()throws SQLException,ClassNotFoundException{
        Class.forName(jdbcName);
        Connection connection= DriverManager.getConnection( url,user,password);
        return connection;
    }

    /**
     * 释放资源
     */
    public static void close(PreparedStatement statement)throws SQLException{
        try {
            if(statement != null) {
                statement.close();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }


    }
}
